package pers.wensheng.patterns.behavioral_pattern.mediator_pattern.entity.mediator;

import lombok.Getter;
import lombok.Setter;
import pers.wensheng.patterns.behavioral_pattern.mediator_pattern.entity.person.HouseOwner;
import pers.wensheng.patterns.behavioral_pattern.mediator_pattern.entity.person.Person;
import pers.wensheng.patterns.behavioral_pattern.mediator_pattern.entity.person.Tenant;

/**
 *  具体的中介者角色类
 */
@Getter
@Setter
public class MediatorStructure extends Mediator {

    /**
     * 聚合房主和租房对象
     */
    private HouseOwner houseOwner;
    private Tenant tenant;

    /**
     * 沟通
     *  具体实现，只有两个角色
     *  如果传入的是租房者，则一定是和房主沟通的
     * @param
     * @param person
     */
    @Override
    public void constact(String message, Person person) {

        if (person == houseOwner) {          //如果是房主，则租房者获得信息
            tenant.getMessage(message);
        } else {       //反则是房主获得信息
            houseOwner.getMessage(message);
        }

    }

}
